<?php
    header("Content-Type:application/json;charset=UTF-8");
    $connect = mysqli_connect('localhost','root','root','person');

    if (!$connect){
        echo json_encode(['code' => '0','msg' => '连接失败']);
    }

    $sql = "select dname,count(*) as total from staff join department on staff.dep_id = department.id group by dep_id";

    $query = mysqli_query($connect,$sql);

    $data = mysqli_fetch_all($query,MYSQLI_ASSOC);

    $sql1 = "select dname as name ,count(*) as value from staff join department on staff.dep_id = department.id group by dep_id";

    $query1 = mysqli_query($connect,$sql1);

    $res = mysqli_fetch_all($query1,MYSQLI_ASSOC);

    $sql2 = "select salary,create_time from salary";

    $query2 = mysqli_query($connect,$sql2);

    $res1 = mysqli_fetch_all($query2,MYSQLI_ASSOC);

    $xData = [];
    $yData = [];

    foreach ($data as $v){
        $xData[] = $v['dname'];
        $yData[] = $v['total'];

    }

//    $xData1 = [];
//    $yData1 = [];
//
//    foreach ($data as $v){
//        $xData1[] = $v['salary'];
//        $yData1[] = strtotime($v['salary']);
//
//    }


    if($data && $res && $res1){
        echo json_encode(['code' => '1','msg' => '成功','data' => [
            'x' => $xData,
            'y' => $yData,
            'zt' => $res,
            'a' => $xData1,
            'b' => $yData1,

        ]]);
    }



    ?>